package net.oschina.archx.spring.sequoiadb.support;

import com.sequoiadb.base.Sequoiadb;
import net.oschina.archx.spring.sequoiadb.SequoiaFactory;
import net.oschina.archx.spring.sequoiadb.SequoiaSession;
import net.oschina.archx.spring.sequoiadb.session.SequoiaSessionTemplate;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * SequoiaDaoSupport
 *
 * @author Archx
 * @date 2015/6/30 0030
 */
public abstract class SequoiaDaoSupport implements InitializingBean {

    private SequoiaSession sequoiaSession;

    @Resource
    public void setSequoiaFactory(SequoiaFactory sequoiaFactory) {
        this.sequoiaSession = new SequoiaSessionTemplate(sequoiaFactory);
    }

    public SequoiaSession getSession() {
        return sequoiaSession;
    }

    public Sequoiadb getSequoiadb() {
        return sequoiaSession.getSequoiadb();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(sequoiaSession, "无法获取巨杉数据库实例!");
        sequoiaSession.checkConfig();
    }
}
